/*********************************************************
          File Name:16.41.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 19 Dec 2015 07:49:56 PM CST
**********************************************************/

#include <iostream>

// Q: Write a new version `sum`, and its return type is large enough
// to store the result

template<typename T>
auto sum(T a, T b) -> typename std::make_unsigned<decltype(a)>::type
{
        return a + b;
}

int plus(int a, int b)
{
        return a + b;
}

int main()
{
        int a = (1 << 31) - 1;
        int b = a;

        std::cout << sum(a, b) << std::endl;
        // overflow
        std::cout << plus(a, b) << std::endl;

        return 0;
}
